<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/18 0018
 * Time: 下午 14:10
 */

namespace api\models\c2\entity;

use common\helpers\VoteHelper;
use common\models\c2\entity\ActivityModel;
use common\models\c2\entity\ActivityPlayerVoteRecordModel;
use common\models\c2\statics\Whether;
use cza\base\models\statics\ResponseDatum;
use Yii;
use yii\base\Event;
use yii\db\Exception;
use yii\helpers\ArrayHelper;

class VoteRecordModel extends ActivityPlayerVoteRecordModel
{
    const EVENT_VOTE = 'vote';

    public function __construct($config = [])
    {
        $this->on(self::EVENT_VOTE, ['common\models\c2\entity\ActivityPlayerModel', 'obtainVote']);
        parent::__construct($config);
    }

    public function rules()
    {
        return ArrayHelper::merge(parent::rules(), [
            [['user_id', 'activity_player_id'], 'required'],
        ]); // TODO: Change the autogenerated stub
    }


    public function afterSave($insert, $changedAttributes)
    {
        parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
        if ($insert) {
            $this->trigger(self::EVENT_VOTE, new Event());
        }
    }

}